package com.kwedding.service.app;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kwedding.bean.TB_Images;
import com.kwedding.dao.TB_ImagesMapper;
import com.kwedding.dto.app.RequestGetImage;
import com.kwedding.dto.app.ResponseImages;
import com.kwedding.util.CheckedUtil;
import com.kwedding.util.Constants;
import com.kwedding.util.CopyerObject;
import com.kwedding.util.LoggerParent;
import com.kwedding.util.RequestErrorBackException;

@Service
public class ImageService extends LoggerParent {

	@Autowired
	private TB_ImagesMapper tb_ImagesMapper;

	/**
	 * 根据品牌和类型获取图片
	 * 
	 * @param getImage
	 */
	@Transactional(readOnly = true)
	public List<ResponseImages> getImages(RequestGetImage getImage) {
		CheckedUtil.isNull(getImage.getBrandId(), Constants.REQUEST_ERROR_1, "请选择品牌");
		CheckedUtil.isNull(getImage.getType(), Constants.REQUEST_ERROR_2, "请选择类型");
		List<TB_Images> tb_Images = tb_ImagesMapper.selectImagesByBrandIdAndType(getImage.getBrandId(),
				getImage.getType());
		List<ResponseImages> responseImages = new ArrayList<>();
		if (tb_Images != null && tb_Images.size() > 0) {
			tb_Images.stream().forEach(r -> {
				ResponseImages responseImage = CopyerObject.copyerObject(r, ResponseImages.class);
				responseImages.add(responseImage);
			});
			return responseImages;
		} else {
			throw new RequestErrorBackException(Constants.REQUEST_ERROR_1, "品牌图片不存在");
		}
	}

}
